package com.gdust.spzx.common.config;

import com.gdust.spzx.common.interceptor.UserLoginAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ClassName: UserWebMvcConfiguration
 * Package: com.gdust.spzx.common.config
 * Description: 配置类，用于注册拦截器，将 UserLoginAuthInterceptor 拦截器添加到拦截链中
 *
 * @Author syun
 * @Create 2024/12/27 10:32
 * @Version 1.0
 */
public class UserWebMvcConfiguration implements WebMvcConfigurer {
    // 注入自定义的用户登录拦截器
    @Autowired
    private UserLoginAuthInterceptor userLoginAuthInterceptor;

    /**
     * 注册自定义拦截器
     * 通过 addPathPatterns 设置拦截的路径规则
     *
     * @param registry 拦截器注册对象
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 UserLoginAuthInterceptor 拦截器，并指定拦截的路径规则
        registry.addInterceptor(userLoginAuthInterceptor)
                .addPathPatterns("/api/**");// 拦截所有以 /api/** 开头的请求
    }
}
